﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

// Token: 0x0200039F RID: 927
public class SquarePickUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler, IEventSystemHandler
{
	// Token: 0x1700023B RID: 571
	// (get) Token: 0x06001706 RID: 5894 RVA: 0x0009AD48 File Offset: 0x00098F48
	// (set) Token: 0x06001707 RID: 5895 RVA: 0x0009AD50 File Offset: 0x00098F50
	public Vector2 Value
	{
		get
		{
			return this.value;
		}
		set
		{
			this.SetValue(value);
		}
	}

	// Token: 0x06001708 RID: 5896 RVA: 0x0009AD5C File Offset: 0x00098F5C
	public void SetValue(Vector2 val)
	{
		this.value = val;
		this.ValToPoint();
		this.OnChangeValue();
	}

	// Token: 0x06001709 RID: 5897 RVA: 0x0009AD74 File Offset: 0x00098F74
	public void OnPointerDown(PointerEventData eventData)
	{
		if (this.isDragging)
		{
			return;
		}
		this.CursorPosToVal(eventData.position);
	}

	// Token: 0x0600170A RID: 5898 RVA: 0x0009AD90 File Offset: 0x00098F90
	public void OnBeginDrag(PointerEventData eventData)
	{
		this.CursorPosToVal(eventData.position);
		this.isDragging = true;
	}

	// Token: 0x0600170B RID: 5899 RVA: 0x0009ADA8 File Offset: 0x00098FA8
	public void OnDrag(PointerEventData eventData)
	{
		this.CursorPosToVal(eventData.position);
		this.isDragging = true;
	}

	// Token: 0x0600170C RID: 5900 RVA: 0x0009ADC0 File Offset: 0x00098FC0
	public void OnEndDrag(PointerEventData eventData)
	{
		this.isDragging = false;
	}

	// Token: 0x0600170D RID: 5901 RVA: 0x0009ADCC File Offset: 0x00098FCC
	private void CursorPosToVal(Vector2 cursorPos)
	{
		Vector2 vector = this.area.InverseTransformPoint(cursorPos);
		this.value.x = Mathf.InverseLerp(this.area.rect.xMin, this.area.rect.xMax, vector.x);
		this.value.y = Mathf.InverseLerp(this.area.rect.yMin, this.area.rect.yMax, vector.y);
		this.ValToPoint();
		this.OnChangeValue();
	}

	// Token: 0x0600170E RID: 5902 RVA: 0x0009AE78 File Offset: 0x00099078
	private void ValToPoint()
	{
		Vector2 anchoredPosition;
		anchoredPosition.x = this.area.rect.size.x * this.value.x;
		anchoredPosition.y = this.area.rect.size.y * this.value.y;
		this.pointImg.rectTransform.anchoredPosition = anchoredPosition;
	}

	// Token: 0x0600170F RID: 5903 RVA: 0x0009AEF4 File Offset: 0x000990F4
	private void OnChangeValue()
	{
		if (this.onChangeAction != null)
		{
			this.onChangeAction(this.value);
		}
	}

	// Token: 0x06001710 RID: 5904 RVA: 0x0009AF14 File Offset: 0x00099114
	public void SetOnChangeAction(Action<Vector2> action)
	{
		this.onChangeAction = action;
	}

	// Token: 0x04001AD8 RID: 6872
	[SerializeField]
	private RectTransform area;

	// Token: 0x04001AD9 RID: 6873
	[SerializeField]
	private Image pointImg;

	// Token: 0x04001ADA RID: 6874
	private bool isDragging;

	// Token: 0x04001ADB RID: 6875
	private Vector2 value;

	// Token: 0x04001ADC RID: 6876
	private Action<Vector2> onChangeAction;
}
